package com.example.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @ClassName Swagger2Config
 * @Description TODO
 * @Author hello
 * @Date 2020/4/14 9:23
 * @Version 1.0
 */
@Configuration
public class Swagger2Config {

    @Value("${swagger.switch}")
    private Boolean swaggerSwitch;

    @Bean
    public Docket networkApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .enable(swaggerSwitch)
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors
                        .withClassAnnotation(Controller.class))
                .build().apiInfo(networkApiInfo());
    }

    private ApiInfo networkApiInfo() {
        ApiInfo apiInfo = new ApiInfo(
                "网络系统",
                "network Platform's REST API, for system administrator",
                "1.0",
                "NO terms of service", new Contact("test",
                "http://www.demo.com", "hellomamingcong@163.com"),
                "The Apache License, Version 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0.html"
        );
        return apiInfo;
    }

}
